package com.nep.NEPM.controller;

import com.nep.common.util.SceneSwitcherUtil;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

public class AQITrendTotalStatisViewController {
    @FXML
    private Button btn_OUT;
    @FXML
    private Button btn_Supervisor;
    @FXML
    private Button btn_ConfirmAQI;
    @FXML
    private Button btn_ProvinceGro;

    @FXML
    private TableView<AQITrendData> tableView;
    @FXML
    private TableColumn<AQITrendData, Integer> idColumn;
    @FXML
    private TableColumn<AQITrendData, String> monthColumn;
    @FXML
    private TableColumn<AQITrendData, Integer> exceededColumn;

    /**
     * 初始化方法，在界面加载时自动调用
     */
    @FXML
    private void initialize() {
        // 配置表格列与数据模型的映射关系
        idColumn.setCellValueFactory(new PropertyValueFactory<>("id"));
        monthColumn.setCellValueFactory(new PropertyValueFactory<>("month"));
        exceededColumn.setCellValueFactory(new PropertyValueFactory<>("exceededCount"));

        // 加载AQI超标趋势示例数据
        ObservableList<AQITrendData> data = FXCollections.observableArrayList(
                new AQITrendData(1, "1月", 12),
                new AQITrendData(2, "2月", 8),
                new AQITrendData(3, "3月", 15),
                new AQITrendData(4, "4月", 7),
                new AQITrendData(5, "5月", 5),
                new AQITrendData(6, "6月", 3),
                new AQITrendData(7, "7月", 2),
                new AQITrendData(8, "8月", 1),
                new AQITrendData(9, "9月", 4),
                new AQITrendData(10, "10月", 6),
                new AQITrendData(11, "11月", 9),
                new AQITrendData(12, "12月", 11)
        );

        tableView.setItems(data);
    }

    /**
     * 返回上一级界面
     */
    @FXML
    private void OutToMain() {
        SceneSwitcherUtil.switchScene(btn_OUT, "/com/nep/NEPM/view/IndexView.fxml");
    }

    /**
     * 跳转到公众监督数据列表
     */
    @FXML
    private void toSupervisorList() {
        SceneSwitcherUtil.switchScene(btn_Supervisor, "/com/nep/NEPM/view/SupervisorListView.fxml");
    }

    /**
     * 跳转到确认AQI数据列表
     */
    @FXML
    private void toConfirmAQIList() {
        SceneSwitcherUtil.switchScene(btn_ConfirmAQI, "/com/nep/NEPM/view/ConfirmAQIListView.fxml");
    }

    /**
     * 跳转到省分组检查统计
     */
    @FXML
    private void toProvinceGro() {
        SceneSwitcherUtil.switchScene(btn_ProvinceGro, "/com/nep/NEPM/view/ProvinceGroView.fxml");
    }

    /**
     * AQI趋势数据模型类
     */
    public static class AQITrendData {
        private final Integer id;
        private final String month;
        private final Integer exceededCount;

        public AQITrendData(Integer id, String month, Integer exceededCount) {
            this.id = id;
            this.month = month;
            this.exceededCount = exceededCount;
        }

        public Integer getId() {
            return id;
        }

        public String getMonth() {
            return month;
        }

        public Integer getExceededCount() {
            return exceededCount;
        }
    }
}